#!/bin/bash

#====================================================================
# for、while 循环
#
# 参考：https://www.runoob.com/linux/linux-shell-process-control.html
#====================================================================

for num in 11 22 33 44 55
do
    echo "输出: $num"
done

arrNum=(11 22 33 44 55)
for num in ${arrNum[*]}; do
    echo "值为: $num"
done

i=0
for city in '苏州' '上海' '长沙' '北京'; do
    echo "已去或想去的城市: $city"
    let "i++"
done
echo "循环了$i次"

arrCity=(#元素也可以一行写一个，分行写
    'suzhou'
    'shanghai'
    'changsha'
    'beijing'
)

# 循环输出
echo '循环输出arrCity结果: '
for city in ${arrCity[*]}; do
    echo $city
done

i=0
for str in 'my name is ouyang'; do
    echo "输出字符串: $str"
    let "i++"
done
echo "循环了$i次" #1次

# 多层循环
for i in 

i=0
while true; do
    if [ $i -eq 0 ]; then
        echo "continue跳出本次循环了"
        let "i++"
        continue #跳出本次循环
    fi
    if [ $i -lt 3 ]; then
        echo "break退出循环了"
        break #中止循环
    fi
    let "i++"
done

i=1
sum=0
while [ $i -lt 3 ]; do
    sum=$[ sum + i ]
    let "i++"
done
echo "i=$i"
echo "1到10之和: $sum"

